import Client from "./common";
const getToken = () => {
  return new Promise((resolve,reject)=>{
    let params = new Client.getQueryString(),
        storeToken = Client.getStore("token");
    let nowTime = new Date().getTime(),
        expTime = 1000 * 60 * 60 * 1.8; //1.5h
    if(params.token){
      let cTime = new Date().getTime();
      let tokenObj = {
        token: params.token,
        time: cTime
      }
      Client.setStore("token", tokenObj);
      //console.log('地址栏第一次token信息',tokenObj);
      resolve(tokenObj);
      return;
    }else if(storeToken && (nowTime - storeToken.time < expTime)){
      //console.log('缓存token',storeToken);
      resolve(storeToken);
      return;
    }else{
      //过期处理
      location.href = 'http://localhost:8088/#/login';
    }
  });
}
export default getToken